<template>
  <!-- 商品详情 -->
  <div class="product-details">
    <swiper v-if="goodsBannerList.length > 0" class="carousel" indicator-dots="false" autoplay="true" interval="3000"
      circular="true">
      <swiper-item v-for="(item, index) in goodsBannerList" :key="index">
        <image :src="item" class="carousel-image" />
      </swiper-item>
    </swiper>
    <img v-else src="../static/imgs/banner.png" class="product-details-img" alt="">
    <div class="details-center">
      <div class="title">{{ goodsInfo.goodsName }}</div>
      <div class="bottom">
        <div class="left">
          <span>￥</span>
          <span>{{ goodsInfo.listGoodsSkus?.[0]?.priceStr || goodsInfo.listGoodsSkus?.[0]?.marketPrice || 0 }}</span>
        </div>
        <div v-if="hasSpecifications(goodsInfo)" class="right" @click="showSpecification(goodsInfo)">
          选规格
        </div>
        <!-- 无规格的商品：显示加减数量控件 -->
        <div v-else class="quantity-controls">
          <img v-if="getProductQuantity(goodsInfo) > 0" class="quantity-btn" style="margin-right: 0px;"
            src="../static/imgs/jianhao.png" alt="" @click.stop="decreaseProductQuantity(goodsInfo)">
          <div v-if="getProductQuantity(goodsInfo) > 0" class="quantity-text">{{ getProductQuantity(goodsInfo) }}</div>
          <img class="quantity-btn" style="margin-right: 0px;" src="../static/imgs/Merchant/tianjia2.png" alt=""
            @click.stop="increaseProductQuantity(goodsInfo)">
        </div>
      </div>
    </div>
    <div class="page-line"></div>
    <div class="goods-description">
      <div class="title">商品详情</div>
      <div class="description">
        <span>商家描述：</span>
        {{ goodsInfo.goodsDescription }}
      </div>
    </div>

    <!-- 规格选择弹窗 -->
    <div class="Specification-box" v-if="isShowSpecification">
      <div class="Specification-bj" @click="closeSpecification"> </div>
      <div class="popup-Specification">
        <div class="popup-Specification-header">
          选规格
        </div>
        <div class="Specification-content">
          <template v-for="(spec, specIndex) in currentProduct.specifications" :key="specIndex">
            <div class="Specification-content-item">
              <div class="Specification-content-item-title">{{ spec.name }}</div>
              <div class="Specification-content-item-content">
                <template v-for="(option, optionIndex) in spec.list" :key="optionIndex">
                  <div :class="{ active: selectedSpecs[spec.name] === option.name }"
                    @click.stop="selectSpec(spec.name, option)">
                    {{ option.name }} <span v-if="Number(option.priceStr) > 0" style="color: red;">+￥{{ option.priceStr
                    }}</span>
                  </div>
                </template>
              </div>
            </div>
          </template>
        </div>
        <div class="Specification-footer">
          <div class="Specification-footer-header">
            <div>已选规格：{{ selectedSpecText }}</div>
          </div>
          <div class="Specification-footer-bottom">
            <div class="left">
              <span>￥</span>{{ currentProduct.priceStr }}
            </div>
            <div class="right" @click="addToCart">加入购物车</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 购物车 -->
    <div class="Shopping-cart" v-if="cartItems.length > 0">
      <div class="Shopping-cart-box" @click="toggleCart">
        <div class="Shopping-cart-box-img">
          <img src="../static/imgs/goumai.png" alt="">
          <div class="Shopping-cart-box-img-text">{{ totalQuantity }}</div>
        </div>
        <div class="Shopping-cart-box-text">
          <div class="Shopping-cart-box-text-top">到手约 ￥ <span>{{ totalPrice }}</span></div>
          <div class="Shopping-cart-box-text-bottom">预估配送费¥{{ shopInfo.deliveryFeeStr || 0 }}</div>
        </div>
        <div class="Shopping-cart-box-botton" :class="{ 'active': canCheckout }" @click.stop="checkout">
          {{ checkoutBtnText }}
        </div>
      </div>
    </div>

    <!-- 在现有模板中添加购物车弹窗 -->
    <wd-overlay :show="showCart" @click="showCart = false" :zIndex="10">
      <view class="Shopping-cart-wrapper" @click.stop>
        <div class="wrapper-box">
          <div class="wrapper-box-header">
            <div class="wrapper-box-header-left">
              已选商品
            </div>
            <div class="wrapper-box-header-right" @click="clearCart">
              清空
            </div>
          </div>
          <div class="wrapper-box-content">
            <div class="item-content">
              <template v-for="(item, index) in cartItems" :key="index">
                <div class="item-content-item">
                  <img :src="item.thumbnail" alt="">
                  <div class="item-content-item-title">
                    <div class="one">{{ item.goodsName }}</div>
                    <div class="two">
                      <template v-for="(spec, specIndex) in item.specDetails" :key="specIndex">
                        <span>{{ spec.specsName }} <span v-if="Number(spec.specsPrice) > 0" style="color: red;">+￥{{
                          spec.specsPrice }}</span></span>
                      </template>
                    </div>
                    <div class="four">
                      <div class="four-left">
                        <span>￥</span>
                        <span>{{
                          (parseFloat(item.listGoodsSkus?.[0]?.priceStr || 0) +
                            parseFloat(item.listGoodsSkus?.[0]?.packPriceStr || 0) +
                            parseFloat(item.specAdditionalPrice || 0)).toFixed(2)
                        }}</span>
                        <span v-if="Number(item.listGoodsSkus?.[0]?.packPriceStr) > 0"
                          style="font-size: 20rpx; margin-left: 8rpx;">+打包费¥{{ item.listGoodsSkus?.[0]?.packPriceStr
                          }}</span>
                      </div>
                      <div class="four-right">
                        <img class="img-left" src="../static/imgs/jianhao.png" alt="" @click="decreaseQuantity(index)">
                        <div>{{ item.quantity }}</div>
                        <img class="img-right" src="../static/imgs/Merchant/tianjia2.png" alt=""
                          @click="increaseQuantity(index)">
                      </div>
                    </div>
                  </div>
                </div>
              </template>
            </div>
          </div>
        </div>
      </view>
    </wd-overlay>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';

// 店铺id
const shopId = ref('')
// 商品id
const goodsId = ref('')

// 规格选择相关变量
const isShowSpecification = ref(false)
const currentProduct = ref({})
const selectedSpecs = ref({})
const cartItems = ref([])

// 购物车相关变量
const showCart = ref(false)

// 计算属性
const selectedSpecText = computed(() => {
  const specs = Object.values(selectedSpecs.value)
  return specs.length > 0 ? specs.join('，') : '请选择规格'
})

const totalQuantity = computed(() => {
  return cartItems.value.reduce((total, item) => total + item.quantity, 0)
})

// 计算属性
const totalPrice = computed(() => {
  const subtotal = cartItems.value.reduce((total, item) => {
    const priceStr = parseFloat(item.listGoodsSkus?.[0]?.priceStr) || 0;  // 保证为数字，若为非数字则默认为0
    const packPriceStr = parseFloat(item.listGoodsSkus?.[0]?.packPriceStr) || 0;   // 获取打包费，转换为数字，如果无效则默认为0
    const specAdditionalPrice = parseFloat(item.specAdditionalPrice) || 0; // 加上规格额外价格
    const quantity = parseInt(item.quantity, 10) || 0;  // 确保数量是数字，若不是则默认为0
    return total + ((priceStr + packPriceStr + specAdditionalPrice) * quantity);
  }, 0);

  // const deliveryFeeStr = parseFloat(shopInfo.value.deliveryFeeStr) || 0;  // 确保配送费是数字，若无效则为0
  const total = subtotal;

  return total.toFixed(2);  // 最终结果保留2位小数
});

// 获取商品在购物车中的数量
const getProductQuantity = (product) => {
  // 从购物车数据中查找对应商品的数量
  const cartItem = cartItems.value.find(item => {
    // 匹配商品ID
    return item.goodsId === product.goodsId
  })
  return cartItem ? cartItem.quantity : 0
}

// 增加无规格商品数量
const increaseProductQuantity = (product) => {
  const existingIndex = cartItems.value.findIndex(item =>
    item.goodsId === product.goodsId && item.specifications.length === 0
  )

  if (existingIndex >= 0) {
    cartItems.value[existingIndex].quantity += 1
  } else {
    // 创建新的购物车项
    const cartItem = {
      goodsId: product.goodsId,
      goodsName: product.goodsName,
      thumbnail: product.thumbnail,
      specifications: [],
      quantity: 1,
      listGoodsSkus: product.listGoodsSkus
    }
    cartItems.value.push(cartItem)
  }
}

// 减少无规格商品数量
const decreaseProductQuantity = (product) => {
  const existingIndex = cartItems.value.findIndex(item =>
    item.goodsId === product.goodsId && item.specifications.length === 0
  )

  if (existingIndex >= 0) {
    if (cartItems.value[existingIndex].quantity > 1) {
      cartItems.value[existingIndex].quantity -= 1
    } else {
      cartItems.value.splice(existingIndex, 1)
    }
  }
}
const mandatoryChoiceObject = ref({})
const shopInfo = ref({})
// 加载onload
onLoad((options) => {
  goodsId.value = options.goodsId
  shopId.value = options.shopId
  getGoodsInfo(goodsId.value)

  // 从URL参数解析购物车数据
  if (options.cartData) {
    try {
      cartItems.value = JSON.parse(decodeURIComponent(options.cartData));
    } catch (e) {
      console.error('解析购物车数据出错:', e);
      cartItems.value = [];
    }
  }
  // 从URL参数解析店铺信息数据
  if (options.shopInfo) {
    try {
      shopInfo.value = JSON.parse(decodeURIComponent(options.shopInfo));
    } catch (e) {
      console.error('解析店铺信息数据出错:', e);

    }
  }
  if (options.mandatoryChoiceObject) {
    mandatoryChoiceObject.value = JSON.parse(decodeURIComponent(options.mandatoryChoiceObject));
  }
})

// 在onUnload中也添加发送
onUnload(() => {
  uni.$emit('updateCart', cartItems.value);
});

// 商品详情
const goodsInfo = ref({})
const goodsBannerList = ref([])
const getGoodsInfo = async (goodsId) => {
  const res = await Fetch(`shopping/goodsInfo/${goodsId}`, {
    method: 'get',
  })
  if (res.data.code === 200) {
    if (res.data.data.bannerImgs) {
      const imgList = res.data.data.bannerImgs?.split(',') || []
      goodsBannerList.value = imgList
    }
    goodsInfo.value = res.data.data
  } else {
    uni.showToast({
      title: res.data?.msg || '',
      icon: 'none',
    })
  }
}

// 判断商品是否有规格
const hasSpecifications = (product) => {

  if (!product.listGoodsSkus?.[0]?.skuDesc) return false;
  try {
    const list = JSON.parse(product.listGoodsSkus?.[0]?.skuDesc)

    return list && list.length > 0
  } catch (e) {
    console.error('Error parsing skuDesc:', e)
    return false
  }
}

// 显示规格选择
const showSpecification = (product) => {
  const SpecificationList = product.goodsSpecsList
  console.log(SpecificationList, 'SpecificationList');
  currentProduct.value = product
  currentProduct.value.priceStr = product.listGoodsSkus?.[0].marketPrice || product.listGoodsSkus?.[0].priceStr
  currentProduct.value.specifications = SpecificationList
  selectedSpecs.value = {}
  isShowSpecification.value = true
}

// 关闭规格选择
const closeSpecification = () => {
  isShowSpecification.value = false
  selectedSpecs.value = {}
}

// 选择规格
const selectSpec = (specName, option) => {
  selectedSpecs.value[specName] = option.name

  // 重新计算价格：基础价格 + 所有已选规格的额外价格
  const basePrice = parseFloat(currentProduct.value.listGoodsSkus?.[0]?.marketPrice || currentProduct.value.listGoodsSkus?.[0]?.priceStr || 0)

  // 计算所有规格选项的额外价格
  let additionalPrice = 0
  currentProduct.value.specifications.forEach(spec => {
    const selectedOption = spec.list.find(opt => opt.name === selectedSpecs.value[spec.name])
    if (selectedOption && selectedOption.priceStr) {
      additionalPrice += parseFloat(selectedOption.priceStr)
    }
  })

  // 更新当前商品显示的价格
  currentProduct.value.priceStr = (basePrice + additionalPrice).toFixed(2)
}

// 添加到购物车
const addToCart = () => {
  // 检查是否选择了所有规格
  const requiredSpecs = currentProduct.value.specifications.map(spec => spec.name)
  const selectedSpecNames = Object.keys(selectedSpecs.value)

  if (selectedSpecNames.length !== requiredSpecs.length) {
    uni.showToast({
      title: '请选择完整规格',
      icon: 'none'
    })
    return
  }
  // 构建规格详情数组（包含名称和价格）
  const specDetails = []
  let specAdditionalPrice = 0
  currentProduct.value.specifications.forEach(spec => {
    const selectedOption = spec.list.find(opt => opt.name === selectedSpecs.value[spec.name])
    if (selectedOption) {
      specDetails.push({
        optionName: spec.name,
        specsId: selectedOption.id,
        specsName: selectedOption.name,
        specsPrice: selectedOption.priceStr || 0
      })
      specAdditionalPrice += parseFloat(selectedOption.priceStr || 0)
    }
  })

  const cartItem = {
    ...currentProduct.value,
    goodsId: currentProduct.value.goodsId,
    goodsName: currentProduct.value.goodsName,
    thumbnail: currentProduct.value.thumbnail,
    categoryName: currentProduct.value.categoryName,
    categoryId: currentProduct.value.categoryId,
    specifications: Object.values(selectedSpecs.value), // 只保存规格名称用于显示
    specDetails: specDetails, // 保存完整规格信息（包含价格）
    quantity: 1,
    listGoodsSkus: currentProduct.value.listGoodsSkus,
    specAdditionalPrice: specAdditionalPrice // 保存规格额外价格
  }

  // 检查购物车中是否已存在相同商品
  const existingIndex = cartItems.value.findIndex(item =>
    item.name === cartItem.name &&
    JSON.stringify(item.specifications) === JSON.stringify(cartItem.specifications)
  )

  if (existingIndex >= 0) {
    cartItems.value[existingIndex].quantity += 1
  } else {
    cartItems.value.push(cartItem)
  }

  closeSpecification()
  uni.showToast({
    title: '已加入购物车',
    icon: 'success'
  })
}

// 购物车方法
const toggleCart = () => {
  showCart.value = !showCart.value
}

const clearCart = () => {
  cartItems.value = []
  showCart.value = false
  uni.showToast({
    title: '购物车已清空',
    icon: 'success'
  })
}

const increaseQuantity = (index) => {
  cartItems.value[index].quantity += 1
}

const decreaseQuantity = (index) => {
  if (cartItems.value[index].quantity > 1) {
    cartItems.value[index].quantity -= 1
  } else {
    cartItems.value.splice(index, 1)
    if (cartItems.value.length === 0) {
      showCart.value = false
    }
  }
}

const checkout = async () => {
  if (!canCheckout.value) {
    uni.showToast({
      title: '未达到起送金额',
      icon: 'none'
    })
    return
  }

  // 检查是否有必选分类，并判断购物车中是否包含必选分类的商品
  if (mandatoryChoiceObject.value && mandatoryChoiceObject.value.categoryId) {
    const hasMandatoryProduct = cartItems.value.some(item =>
      item.categoryId === mandatoryChoiceObject.value.categoryId
    )

    if (!hasMandatoryProduct) {
      // 找到必选分类在 categories 中的索引
      uni.showToast({
        title: `请选择必选商品：${mandatoryChoiceObject.value.categoryName || '必选分类'}`,
        icon: 'none',
        duration: 2000
      })
      return
    }
  }
  const result = await Fetch(`shopping/login/getUserInfo`)
  if (result.data.code === 200) {

    // 跳转到支付页面
    uni.redirectTo({
      url: '/pages/Payment?cartData=' + encodeURIComponent(JSON.stringify(cartItems.value)) + '&deliveryFeeStr=' + shopInfo.value.deliveryFeeStr,
    })
  } else {
    uni.showModal({
      title: '提示',
      content: '您尚未登录，请先登录',
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          // 返回登录页
          uni.reLaunch({
            url: '/pages/login'
          });
        }
      }
    });
  }

}

// 计算属性
const cartTotalPrice = computed(() => {
  return cartItems.value.reduce((total, item) => {
    const priceStr = parseFloat(item.listGoodsSkus?.[0]?.priceStr) || 0
    const packPriceStr = parseFloat(item.listGoodsSkus?.[0]?.packPriceStr) || 0
    const quantity = parseInt(item.quantity, 10) || 0
    return total + ((priceStr + packPriceStr) * quantity)
  }, 0).toFixed(2)
})

const canCheckout = computed(() => {
  const subtotal = cartItems.value.reduce((total, item) => {
    const priceStr = parseFloat(item.listGoodsSkus?.[0]?.priceStr) || 0;  // 保证为数字，若为非数字则默认为0
    const packPriceStr = parseFloat(item.listGoodsSkus?.[0]?.packPriceStr) || 0;  // 同上
    const specAdditionalPrice = parseFloat(item.specAdditionalPrice) || 0; // 加上规格额外价格
    const quantity = parseInt(item.quantity, 10) || 0;  // 确保数量是数字，若不是则默认为0
    return total + ((priceStr + packPriceStr + specAdditionalPrice) * quantity);
  }, 0);

  // 获取起送价，如果没有则默认为0
  const startFeeStr = parseFloat(shopInfo.value.startFeeStr) || 0;

  // 获取配送费
  // const deliveryFeeStr = parseFloat(shopInfo.value.deliveryFeeStr) || 0;

  // 计算总金额（商品小计 + 配送费）
  const totalAmount = subtotal;

  // 只有总金额（含配送费）超过起送价才能结算
  return totalAmount >= startFeeStr;
})

const checkoutBtnText = computed(() => {
  const startFeeStr = parseFloat(shopInfo.value.startFeeStr) || 0;
  if (startFeeStr === 0) return '去结算';

  const subtotal = cartItems.value.reduce((total, item) => {
    const priceStr = parseFloat(item.listGoodsSkus?.[0]?.priceStr) || 0;
    const packPriceStr = parseFloat(item.listGoodsSkus?.[0]?.packPriceStr) || 0;
    const specAdditionalPrice = parseFloat(item.specAdditionalPrice) || 0; // 加上规格额外价格
    const quantity = parseInt(item.quantity, 10) || 0;
    return total + ((priceStr + packPriceStr + specAdditionalPrice) * quantity);
  }, 0);

  // 获取配送费
  // const deliveryFeeStr = parseFloat(shopInfo.value.deliveryFeeStr) || 0;

  // 计算总金额（商品小计 + 配送费）
  const totalAmount = subtotal;

  if (totalAmount >= startFeeStr) {
    return '去结算';
  } else {
    return `¥${startFeeStr}起送`;
  }
})


const goToCheckout = () => {
  if (!canCheckout.value) {
    uni.showToast({
      title: '未达到起送金额',
      icon: 'none'
    })
    return
  }

  // 跳转到结算页面
  uni.navigateTo({
    url: `/pages/Payment?cartData=${encodeURIComponent(JSON.stringify(cartItems.value))}&deliveryFeeStr=${shopInfo.value?.deliveryFeeStr}&serviceChargeStr=${shopInfo.value?.serviceChargeStr}`
  })
}
</script>

<style lang="scss" scoped>
.product-details {
  .product-details-img {
    width: 750rpx;
    height: 478rpx;
  }

  .details-center {
    padding: 30rpx;
    box-sizing: border-box;

    .title {
      height: 48rpx;
      font-weight: bold;
      font-size: 34rpx;
      color: #000000;
      line-height: 48rpx;
      margin-bottom: 14rpx;
    }

    .center {
      margin-bottom: 24rpx;
      font-size: 22rpx;
      color: #989794;
    }

    .bottom {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .left {
        height: 56rpx;
        font-weight: bold;
        font-size: 40rpx;
        color: #EA5838;
        line-height: 56rpx;

        label {
          &:nth-child(1) {
            font-size: 24rpx;
          }
        }
      }

      .right {
        width: 164rpx;
        height: 58rpx;
        background: #F9E149;
        border-radius: 8rpx 8rpx 8rpx 8rpx;
        font-size: 24rpx;
        font-weight: bold;
        color: #191919;
        line-height: 58rpx;
        text-align: center;
      }
    }
  }

  .page-line {
    width: 750rpx;
    height: 20rpx;
    background: #F5F5F5;
  }

  .goods-description {
    padding: 64rpx 30rpx 0 30rpx;

    .title {
      font-weight: bold;
      font-size: 34rpx;
      color: #000000;
      line-height: 48rpx;
      text-align: left;
      font-style: normal;
      text-transform: none;
      margin-bottom: 14rpx;
    }

    .description {
      font-size: 26rpx;
      color: #32312D;
      line-height: 36rpx;
      text-align: left;
      font-style: normal;
      text-transform: none;

      label {
        font-size: 26rpx;
        color: #989794;
      }
    }
  }

  /* 规格选择样式 */
  .Specification-box {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;

    .Specification-bj {
      width: 100%;
      height: 100vh;
      background: rgba(0, 0, 0, 0.5);
      position: fixed;
      z-index: 99;
      top: 0;
      left: 0;
    }

    .popup-Specification {
      width: 692rpx;
      background: #FFFFFF;
      border-radius: 36rpx 36rpx 36rpx 36rpx;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      z-index: 101;

      .popup-Specification-header {
        width: 692rpx;
        height: 96rpx;
        background: #FAFAFA;
        border-radius: 36rpx 36rpx 0rpx 0rpx;
        padding: 20rpx 34rpx;
        box-sizing: border-box;
        font-weight: bold;
        font-size: 40rpx;
        color: #000000;
        line-height: 56rpx;
        text-transform: none;
      }

      .Specification-content {
        padding: 24rpx 34rpx;
        box-sizing: border-box;

        .Specification-content-item {
          margin-bottom: 44rpx;

          .Specification-content-item-title {
            height: 36rpx;
            font-weight: bold;
            font-size: 26rpx;
            color: #000000;
            line-height: 36rpx;
            text-transform: none;
            margin-bottom: 16rpx;
          }

          .Specification-content-item-content {
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            view {
              font-weight: 400;
              font-size: 26rpx;
              color: #37393B;
              text-transform: none;
              padding: 18rpx 26rpx;
              border-radius: 16rpx;
              background: #F6F6F7;
              box-sizing: border-box;
              margin-right: 16rpx;
              margin-bottom: 10rpx;
            }

            .active {
              background: #F9E149;
            }
          }
        }
      }

      .Specification-footer {
        background: #FAFAFA;
        border-radius: 0 0 36rpx 36rpx;

        .Specification-footer-header {
          height: 60rpx;
          font-weight: 400;
          font-size: 22rpx;
          color: #222425;
          line-height: 60rpx;
          padding-left: 32rpx;
          box-sizing: border-box;
          text-transform: none;
        }

        .Specification-footer-bottom {
          border-top: 1rpx solid #F1F1F2;
          display: flex;
          align-items: center;
          height: 92rpx;
          padding: 0 34rpx 0 32rpx;
          box-sizing: border-box;

          .left {
            height: 56rpx;
            font-weight: bold;
            font-size: 40rpx;
            color: #222425;
            line-height: 56rpx;
            text-transform: none;

            label {
              height: 32rpx;
              font-size: 22rpx;
              color: #222425;
              line-height: 32rpx;
              text-transform: none;
            }
          }

          .right {
            width: 178rpx;
            height: 56rpx;
            background: #FBE665;
            border-radius: 28rpx 28rpx 28rpx 28rpx;
            font-weight: bold;
            font-size: 22rpx;
            color: #222425;
            line-height: 56rpx;
            text-align: center;
            text-transform: none;
            margin-left: auto;
          }
        }
      }
    }
  }

  .Shopping-cart {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 166rpx;
    background: #FFFFFF;
    z-index: 100;
    padding: 22rpx 30rpx 64rpx 30rpx;
    box-sizing: border-box;

    .Shopping-cart-box {
      display: flex;
      align-items: center;

      .Shopping-cart-box-img {
        position: relative;

        .Shopping-cart-box-img-text {
          position: absolute;
          top: -10rpx;
          right: -10rpx;
          padding: 2rpx 14rpx;
          color: white;
          border-radius: 50%;
          background: #EB4E27;
        }
      }

      .Shopping-cart-box-text {
        .Shopping-cart-box-text-top {
          height: 36rpx;
          font-weight: bold;
          font-size: 26rpx;
          color: #EB4E36;
          margin-left: 32rpx;
          line-height: 36rpx;

          label {
            font-size: 40rpx;
          }

          margin-bottom: 10rpx;
        }

        .Shopping-cart-box-text-bottom {
          height: 28rpx;
          font-size: 20rpx;
          color: #676869;
          line-height: 28rpx;
          margin-left: 32rpx;
        }
      }

      .Shopping-cart-box-botton {
        width: 200rpx;
        height: 90rpx;
        background: #BCBCBD;
        border-radius: 46rpx 46rpx 46rpx 46rpx;
        font-weight: bold;
        font-size: 36rpx;
        line-height: 90rpx;
        color: #FFFFFF;
        text-align: center;
        margin-left: auto;

        &.active {
          background: #F9DC40;
          color: #000000;
        }
      }
    }

    image {
      width: 74rpx;
      height: 80rpx;
    }
  }

  /* 购物车弹窗样式 - 复用 Merchant 页面的样式 */
  .Shopping-cart-wrapper {
    width: 750rpx;
    background: #F1F1F1;
    border-radius: 36rpx 36rpx 0rpx 0rpx;
    padding: 20rpx;
    box-sizing: border-box;
    position: fixed;
    bottom: 120rpx;

    .wrapper-box {
      width: 710rpx;
      background: #FFFFFF;
      border-radius: 30rpx;
      padding: 30rpx;
      box-sizing: border-box;
      margin: 0 auto;

      .wrapper-box-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 40rpx;

        .wrapper-box-header-left {
          height: 44rpx;
          font-weight: bold;
          font-size: 32rpx;
          color: #222425;
          line-height: 44rpx;
        }

        .wrapper-box-header-right {
          height: 34rpx;
          font-weight: 400;
          font-size: 24rpx;
          color: #999999;
          line-height: 34rpx;
          cursor: pointer;
        }
      }

      .wrapper-box-content {
        .item-content {
          .item-content-item {
            display: flex;
            margin-bottom: 40rpx;

            image {
              width: 128rpx;
              height: 132rpx;
              border-radius: 16rpx 16rpx 16rpx 16rpx;
              margin-right: 20rpx;
            }

            .item-content-item-title {
              flex: 1;
              width: 100%;

              .one {
                height: 40rpx;
                font-weight: bold;
                font-size: 28rpx;
                color: #000000;
                line-height: 40rpx;
                text-transform: none;
              }

              .two {
                height: 34rpx;
                font-weight: 400;
                font-size: 24rpx;
                color: #999999;
                line-height: 34rpx;
                text-transform: none;
              }

              .four {
                display: flex;
                align-items: flex-end;
                width: 100%;

                image {
                  width: 46rpx;
                  height: 46rpx;
                }

                .four-left {
                  margin-right: auto;
                  margin-top: 30rpx;
                  height: 44rpx;
                  font-weight: bold;
                  font-size: 32rpx;
                  color: #EA5838;
                  line-height: 44rpx;
                  text-transform: none;

                  label {
                    &:nth-child(1) {
                      height: 34rpx;
                      font-weight: bold;
                      font-size: 24rpx;
                      color: #EA5838;
                      line-height: 34rpx;
                      text-transform: none;
                    }
                  }
                }
              }

              .four-right {
                display: flex;
                align-items: center;

                .img-left,
                .img-right {
                  width: 46rpx;
                  height: 46rpx;
                  margin: 0rpx;
                }

                .img-left {
                  margin-right: 20rpx;
                }

                .img-right {
                  margin-left: 20rpx;
                }
              }
            }
          }
        }
      }
    }

    .cart-footer {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding-top: 24rpx;
      border-top: 1rpx solid #F1F1F1;

      .cart-total {
        font-size: 28rpx;
        color: #191919;
        font-weight: bold;

        .delivery-fee {
          font-size: 24rpx;
          color: #999;
          margin-left: 16rpx;
        }
      }

      .checkout-btn {
        width: 200rpx;
        height: 80rpx;
        border-radius: 40rpx;
        font-size: 28rpx;
        font-weight: bold;
        border: none;
        cursor: pointer;

        &.active {
          background: #F9DC40;
          color: #000000;
        }

        &:not(.active) {
          background: #BCBCBD;
          color: #FFFFFF;
          cursor: not-allowed;
        }
      }
    }
  }

  .quantity-controls {
    display: flex;
    align-items: center;

    .quantity-btn {
      width: 46rpx;
      height: 46rpx;
      cursor: pointer;
    }

    .quantity-text {
      width: 60rpx;
      height: 46rpx;
      font-size: 24rpx;
      font-weight: bold;
      color: #000000;
      line-height: 46rpx;
      text-align: center;
      margin: 0 8rpx;
    }
  }

  .carousel-container {
    width: 100%;
    height: 200px;
    /* 可以根据需要调整高度 */
  }

  .carousel {
    height: 478rpx;
  }

  .carousel-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* 确保图片等比填充 */
  }
}
</style>
